package com.shuoyue.ycgk.utils;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class NumberUtils {
    public static String getFloat(float f) {
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(2);
        String num = nf.format(f);
        return num;
//        return String.valueOf(f);
    }

    public static String getDouble(double d) {
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(2);
        return nf.format(d);
    }

    /**
     * 多少万
     *
     * @param num
     * @return
     */
    public static String getNumOfWan(int num) {
        if (num < 10000) {
            return String.valueOf(num);
        } else {
            float wan = ((float) num) / 10000;
            String format = new DecimalFormat("#.0").format(wan);
            return format + "万";
        }
    }
}
